package com.knife.blog.logic.impl;

import com.knife.blog.domain.BlogTemplate;
import com.knife.blog.logic.BlogTemplateService;
import com.knife.web.tools.DbPageList;
import com.knife.web.tools.IPageList;

public class BlogTemplateServiceImpl extends DAOSupportService implements BlogTemplateService {
	private static BlogTemplateServiceImpl blogTemplateService = new BlogTemplateServiceImpl();
	
	public static BlogTemplateServiceImpl getInstance() {
		return blogTemplateService;
	}
	
	public IPageList queryTemplate(int updated, String key, int currentPage,
			int pageSize){
		String scope = "updated=? order by inputtime desc";
		java.util.Collection paras = new java.util.ArrayList();
		paras.add(updated);
		DbPageList pList = new DbPageList(BlogTemplate.class, scope,paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}
	public IPageList queryTemplate(String username,int currentPage,	int pageSize){
		String scope=" 1=1 ";
		if(username!=null&&!("").equals(username)){
		 scope = "inputuser=? order by inputtime desc";
		}
		java.util.Collection<Object> paras = new java.util.ArrayList<Object>();
		if(username!=null&&!("").equals(username)){
			paras.add(username);
		}
		DbPageList pList = new DbPageList(BlogTemplate.class,scope,paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}
	
	public IPageList queryTemplate(BlogTemplate blogTemplate, int currentPage, int pageSize){
		String scope = "cid=? ";
		java.util.Collection<Object> paras = new java.util.ArrayList<Object>();
		paras.add(blogTemplate.getCid());
		DbPageList pList = new DbPageList(BlogTemplate.class, scope, paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}
	
	public boolean addTemplate(BlogTemplate blogTemplate){
		return this.dao.save(blogTemplate);
	}
	
	public boolean delTemplate(String cid){
		return this.dao.del(this.getBlogTemplate(cid));
	}
	
	public BlogTemplate getBlogTemplate(String cid){
		return (BlogTemplate)this.dao.get(BlogTemplate.class,cid);
	}
	
	
}
